// hyb_yl/mysubpages/pages/huanzhe/huanzhe.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    user_list:[],
    openid_list:[],
    user:false
  },
  go_fenzu: function (e) {
    var that = this
    var fenzu = e.currentTarget.dataset.fenzu
    var zid = that.data.zid
    var fzid = e.currentTarget.dataset.fzid
    var openid =e.currentTarget.dataset.openid
    wx.navigateTo({
      url: '/hyb_yl/mysubpages/pages/fenzu/fenzu?fenzu=' + fenzu + '&zid=' + zid + '&fzid=' + fzid+'&openid='+openid,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    var zid = options.zid
    var type = options.type
    that.setData({
      zid: zid,
      type: type,
    })
    
  },
  quxiao:function(){
    this.setData({
      user:false
    })
  },
  getUser:function(e){
    var that = this;
    app.util.request({
      'url':"entry/wxapp/follow.fz_user",
      data:{
        zid:that.data.zid,
        type:that.data.type
      },
      success:function(res)
      {
        that.setData({
          list:res.data
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getUser();
    this.getUsers();
  },
  check_user:function(e){
    var that = this;
    wx.navigateTo({
      url: '/hyb_yl/doctorHome/pages/choose_patient/choose_patient?type='+that.data.type+'&zid='+that.data.zid,
    })
  },
  getUsers:function(e){
    var that = this;
    app.util.request({
      'url':"entry/wxapp/follow.all_qzuser",
      data:{
        zid:that.data.zid,
        type:that.data.type,
      },
      success:function(res)
      {
        that.setData({
          user_list:res.data
        })
      }
    })
  },
  check_list:function(e){
    var that = this;
    var id = e.currentTarget.dataset.id;
    var index = e.currentTarget.dataset.index;
    var openid = e.currentTarget.dataset.openid;
    var zid = that.data.zid;
    var openid_list = that.data.openid_list;
    var user_list=this.data.user_list;
    user_list[index].checked=true
    for(var i=0;i<openid_list.length;i++)
    {
      if(openid_list[i] == openid)
      {
        openid_list.slice(i,1);
      }
    }
    if(openid_list.indexOf(openid) < 0)
    {
      openid_list.push(openid)
    }
    
    that.setData({
      user_list:user_list,
      openid_list:openid_list
    })
  },
  sure:function(){
    var that = this;
    var zid = that.data.zid;
    var openid_list = that.data.openid_list;
    openid_list = JSON.stringify(openid_list)
    var type = that.data.type;
    app.util.request({
      'url':"entry/wxapp/follow.set_fenzu",
      data:{
        openid:openid_list,
        zid:zid,
        type:type
      },
      success:function(res){
        wx.navigateBack({})
      }
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  see(e) {
    var that = this
    var change = e.currentTarget.dataset.change
    var openid = e.currentTarget.dataset.openid
    var titlme = e.currentTarget.dataset.names
    if (change == '1') {
      wx.navigateTo({
        url: '/hyb_yl/zhuanjiasubpages/pages/danganList/danganList?openid=' + openid + '&doc=1' + '&type=1' + '&titlme=' + titlme,
      })
    } else {
      wx.showToast({
        title: '患者未授权',
        icon: 'none'
      })
    }
  },

})